package com.ding.mylib;

public class TextMain3 {
    public static void main(String[] args) throws Exception {
//十六进制编码转中文字符串
        String string = "31";
        String result = stringToGbk(string);
        System.out.println(result);

    }


    //将gbk编码转换成汉字
    public static String stringToGbk(String string) throws Exception {
        byte[] bytes = new byte[string.length() / 2];
        for (int i = 0; i < bytes.length; i++) {
            byte high = Byte.parseByte(string.substring(i * 2, i * 2 + 1), 16);
            byte low = Byte.parseByte(string.substring(i * 2 + 1, i * 2 + 2), 16);
            bytes[i] = (byte) (high << 4 | low);
        }
        String result = new String(bytes, "gbk");
        return result;
    }

}
